const indexApi = require('./mockApi');

const mockApi = [
  indexApi,
];

const handleMiddleware = (app) => {
  mockApi.forEach((apiObj) => {
    for (const item of apiObj) {
      const handleMethod = item.method.toLocaleLowerCase();
      app[handleMethod](item.url, (req, res) => {
        if (typeof (item.handle) === 'function') {
          item.handle(req, res);
        } else {
          res.json(item.data);
        };
      })
    }
  })
}

module.exports = handleMiddleware;